home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: yarrow.wt.com.au!hawk!hawk!wayne
- From: wayne@adied.oz.au (Wayne Elliott)
- Subject: Array Parameters
- Message-ID: <wayne.820650643@hawk>
- Organization: ADI Ltd. - Systems Division
- Date: Wed, 3 Jan 1996 06:30:43 GMT
-
- Can anyone fill me in on whats wrong with the following snippet of
- code. Basically I'm trying to pass and use a multi-dimensional
- array.
-
- -----------------------------------------------------------------
-
- /* Test passing of array parameters */
-
- #include <stdio.h>
-
- char map [][8] =
- {
- "abcdef",
- "ghijkl",
- "mnopqr"
- };
-
- void test(int num, char ** maps)
- {
- int i;
- for(i=0;i<num;i++)
- if(maps[i])
- printf("%04d %s\n", i, maps[i]);
- else
- printf("%04d NULL\n", i);
- }
-
- int main()
- {
- test(3, (char **) map);
- return 0;
- }
-
- -----------------------------------------------------------------
-
- At home this only finds the first element (map[0]).
- At work this gives a core dump.
- Using pointer arithmetic (maps+i) produced something like
-
- 0000 abcedf
- 0001 ef
- 0002 ghijkl
-
- It's all rather comfusing!
- Any clues? How should I be doing this?
-
- Thanks
- Wayne Elliott
-
-